package org.rich.charlesmurphy;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Rich
 *
 */
public class Properties {
	private static Logger log = LoggerFactory.getLogger(Properties.class);
	
	private static java.util.Properties props;
	private static java.util.Properties defaults;
	
	static {
		defaults = new java.util.Properties();
		defaults.put("home.folder", "c:\\");
	}
	
	static void load(File propsFile) {
		InputStream stream = null;
		try {
			stream = new FileInputStream(propsFile);
			load(stream);
		} catch (FileNotFoundException e) {
			handleE(e);
		}
		
	}
	static void load(InputStream stream) {
		try {
			try {
				props = new java.util.Properties(defaults);
				props.load(stream);
			}
			finally {
				if (stream != null) {
					stream.close();
				}			}
		} catch (IOException e) {
			handleE(e);
		}
	}
	private static void handleE(IOException e) {
		props = defaults;
		log.error("Error loading properties from file.  System defaykts will be used.");		
	}

	public static String getFileOpenLocation() {
		return props.getProperty("home.folder");
	}
	
	
	
}
